package com.meilai.project.controller.web.business.customer;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.meilai.project.dto.base.ApiResult;
import com.meilai.project.service.business.customer.CustomerPoolService;
import com.meilai.project.vo.business.customer.BaseCustomerPoolVO;
import com.meilai.project.vo.business.customer.CheckPageCustomerVO;
import com.meilai.project.vo.business.customer.PublicSeaVO;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author xhy
 * @since 2022-09-09
 */
@RestController
@RequestMapping("/api/web/customer/pool")
public class CustomerPoolController {
    @Autowired
    private CustomerPoolService service;

    @ApiModelProperty("客户池列表分页")
    @GetMapping("/page")
    public ApiResult<Page<BaseCustomerPoolVO>> selectPage(@RequestParam(defaultValue = "1", name = "page") Integer page, @RequestParam(defaultValue = "10", name = "page_size") Integer page_size, @RequestParam(required = false, name = "name") String name, @RequestParam(required = false, name = "industry_id") Long industry_id, @ApiParam(name = "type", value = "1:公司盘，2:个人盘") @RequestParam(required = false, name = "type") Integer type) {
        try {
            return ApiResult.ok(service.selectPage(page, page_size, name, industry_id, type));
        } catch (Exception e) {
            return ApiResult.err("查询失败");
        }
    }

    @ApiModelProperty("审核列表,待审核优先显示")
    @GetMapping("/check/record/page")
    public ApiResult<Page<CheckPageCustomerVO>> selectCheckRecordPage(@RequestParam(defaultValue = "1", name = "page") Integer page, @RequestParam(defaultValue = "10", name = "page_size") Integer page_size, @RequestParam(required = false, name = "name") String name, @RequestParam(required = false, name = "industry_id") Long industry_id, @RequestParam(required = false, name = "apply_user_id") Long apply_user_id, @ApiParam(name = "type", value = "1:公司盘，2:个人盘") @RequestParam(required = false, name = "type") Integer type, @RequestParam(name = "status", required = false) Integer status) {
        try {
            return ApiResult.ok(service.selectCheckRecordPage(page, page_size, name, industry_id, apply_user_id, type, status));
        } catch (Exception e) {
            return ApiResult.err("查询失败");
        }
    }

    @ApiModelProperty("公海")
    @GetMapping("/public/sea")
    public ApiResult<Page<PublicSeaVO>> selectPublicSeaPage(@RequestParam(defaultValue = "1", name = "page") Integer page, @RequestParam(defaultValue = "10", name = "page_size") Integer page_size, @RequestParam(required = false, name = "name") String name, @RequestParam(required = false, name = "industry_id") Long industry_id, @ApiParam(name = "type", value = "1:公司盘，2:个人盘") @RequestParam(required = false, name = "type") Integer type) {
        try {
            return ApiResult.ok(service.selectPublicSeaPage(page, page_size, name, industry_id, type));
        } catch (Exception e) {
            return ApiResult.err("查询失败");
        }
    }

    @ApiModelProperty("指派维护")
    @PostMapping("/distribute")
    public ApiResult<Boolean> distribute(@RequestParam("customer_id") Long customer_id, @RequestParam("user_id") Long user_id) {
        try {
            return ApiResult.ok(service.distribute(customer_id, user_id));
        } catch (Exception e) {
            return ApiResult.err("分配失败");
        }
    }

    @ApiModelProperty("解除维护")
    @PostMapping("/relieve")
    public ApiResult<Boolean> relieve(@RequestParam("customer_id") Long customer_id, @RequestParam("type") @ApiParam(name = "type", value = "1:客户池解除，2:自己解除") Integer type) {
        try {
            return ApiResult.ok(service.relieve(customer_id, type));
        } catch (Exception e) {
            return ApiResult.err("解除失败");
        }
    }

    @ApiModelProperty("修改可分配属性")
    @PostMapping("/update/canAssign")
    public ApiResult<Boolean> updateCanAssign(@RequestParam("customer_id") Long customer_id) {
        try {
            return ApiResult.ok(service.updateCanAssign(customer_id));
        } catch (Exception e) {
            return ApiResult.err("操作失败");
        }
    }

    @ApiModelProperty("检查客户的跟进人是否是公司")
    @GetMapping("/checkCustomerMaintain")
    public ApiResult<Boolean> checkCustomerMaintain(@RequestParam("customer_id") Long customer_id) {
        try {
            return ApiResult.ok(service.checkCustomerMaintain(customer_id));
        } catch (Exception e) {
            return ApiResult.err("查询失败");
        }
    }
}
